import { BasicColumn, BasicTable, useTable } from "@/components/Table";
import { useEffect, useState } from "react";
import { productApi } from "@/api/erp/drug/drug";
import { formatDate } from "@/utils/util";
import { useTranslation } from "react-i18next";
let pageNo: Number = 1;
let pageSize: Number = 10;
const index = ({ eqpId, page }: any) => {
	const { t } = useTranslation();
	const en_vi = "drugStorage.equipment.device";
	const [eqpParts, setEqpParts] = useState<any>([]);
	// const schemas: FormSchema[] = [
	// 	{
	// 		label: "编号",
	// 		field: "eqparts",
	// 		component: "Input"
	// 	}
	// ];
	const columns: BasicColumn[] = [
		{
			title: t(`${en_vi}.partNumber`),
			dataIndex: "eqparts",
			render: (eqparts: any) => eqparts.eqpartNo
		},
		{
			title: t(`${en_vi}.name`),
			dataIndex: "eqparts",
			render: (eqparts: any) => eqparts.eqpartName
		},
		{
			title: t(`${en_vi}.type`),
			dataIndex: "eqparts",
			render: (eqparts: any) => eqparts.partTypeName
		},
		{
			title: t(`${en_vi}.price`),
			dataIndex: "eqparts",
			render: (eqparts: any) => eqparts.eqpartPrice
		},
		{
			title: t(`${en_vi}.description`),
			dataIndex: "eqparts",
			render: (eqparts: any) => eqparts.qepartDesc
		},
		{
			title: t(`${en_vi}.batchNumber`),
			dataIndex: "eqparts",
			render: (eqparts: any) => eqparts.batchNo
		},
		{
			title: t(`${en_vi}.productionTime`),
			dataIndex: "eqparts",
			render: (eqparts: any) => formatDate(new Date(eqparts.produceDt))
		},
		{
			title: t(`${en_vi}.warrantyStartTime`),
			dataIndex: "eqparts",
			render: (eqparts: any) => formatDate(new Date(eqparts.startDt))
		},
		{
			title: t(`${en_vi}.warrantyEndTime`),
			dataIndex: "eqparts",
			render: (eqparts: any) => formatDate(new Date(eqparts.endDt))
		}
	];
	const [registerTable, { setPagination }] = useTable({
		dataSource: eqpParts,
		columns,
		useSearchForm: false,
		// formConfig: {
		// 	labelWidth: 120,
		// 	schemas,
		// 	showActionButtonGroup: true,
		// 	showAdvancedButton: false,
		// 	baseColProps: { span: 12 },
		// 	actionColOptions: { span: 24 }
		// },
		bordered: false
	});
	const getEqpPartsPage = async () => {
		const res: any = await productApi.eqpPartsPage({
			pageSize,
			pageNo,
			eqpId
		});
		setEqpParts(res.list);
		setPagination({
			total: res.total,
			onChange: (pageN: Number, pageS: Number) => {
				pageNo = pageN;
				pageSize = pageS;
				console.log(pageN);
				getEqpPartsPage();
			}
		});
	};
	useEffect(() => {
		if (!eqpId) return;
		getEqpPartsPage();
	}, [eqpId]);
	useEffect(() => {
		getEqpPartsPage();
	}, [page]);
	return (
		<div>
			<BasicTable register={registerTable}></BasicTable>
		</div>
	);
};

export default index;
